# -*- encoding:utf-8 -*-
from service.stockdebate.EastdebateCrawler import EastdebateCrawler
from service.stockdebate.StockdebateCrawler import StockdebateCrawler
import utils.FiltRepeatUtil as filt_util
__author__ = 'shudong.msd'

def write_debate_to_db():
    print u'开始 stockdebate sina部分 抓取'

    sdc = StockdebateCrawler()
    count = 0
    # 博客
    # 大盘 11
    sdc.set_target('http://finance.sina.com.cn/blog/7.html')
    count += sdc.writeNewsToDB(11)
    print u'sina 博客 大盘部分 抓取完毕'

    # 个股 12
    sdc.set_target('http://finance.sina.com.cn/blog/15.html')
    count += sdc.writeNewsToDB(12)
    print u'sina 博客 个股部分 抓取完毕'

    # 股吧

    # 大盘 21
    sdc.set_target('http://finance.sina.com.cn/guba/dpfx/49.html')
    count += sdc.writeNewsToDB(21)
    print u'sina 股吧 大盘部分 抓取完毕'

    # 个股 22
    sdc.set_target('http://finance.sina.com.cn/guba/ggjh/1.html')
    count += sdc.writeNewsToDB(22)
    print u'sina 股吧 个股部分 抓取完毕'

    filt_util.filt_repeat('tb_stock_debate')

    print 'ok!!!'
    return count


def write_east_debate_to_db():
    print u'开始 stockdebate east部分 抓取'
    count = 0

    ec = EastdebateCrawler()
    # 博文
    ec.set_target('http://blog.eastmoney.com/24hour.html')
    count += ec.writeNewsToDB(31)
    print u'博文部分 抓取完毕'

    # 股吧
    ec.set_target('http://guba.eastmoney.com/default_1.html')
    count += ec.writeNewsToDB(32)
    ec.set_target('http://guba.eastmoney.com/default_2.html')
    count += ec.writeNewsToDB(32)
    print u'股吧部分 抓取完毕'

    filt_util.filt_repeat('tb_stock_debate')

    print 'ok!!!'

    return count